home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / utils / disk-man / mtools-3.000 / mtools-3 / mtools-3.0 / mmount.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-05-08  |  1.5 KB  |  85 lines

  1. /*
  2.  * Mount an MSDOS disk
  3.  *
  4.  * written by:
  5.  *
  6.  * Alain L. Knaff            
  7.  * Alain.Knaff@inrialpes.fr
  8.  *
  9.  */
  10.  
  11. #include "sysincludes.h"
  12. #include "msdos.h"
  13. #include "mtools.h"
  14.  
  15. #ifdef linux
  16. #include "patchlevel.h"
  17. #include <linux/fd.h>
  18. #include <sys/wait.h>
  19. #include "streamcache.h"
  20. #include "fs.h"
  21.  
  22. extern int errno;
  23.  
  24. void mmount(int argc, char **argv, int type)
  25. {
  26.     char drive;
  27.     int pid;
  28.     int status;
  29.     struct device dev;
  30.     char name[EXPAND_BUF];
  31.     int media;
  32.     struct bootsector boot;
  33.     Stream_t *Stream;
  34.     
  35.     if (argc<2 || !argv[1][0]) {
  36.         fprintf(stderr,"Usage: %s -V drive:\n", argv[0]);
  37.         cleanup_and_exit(1);
  38.     }
  39.     drive = argv[1][0];
  40.     Stream = find_device(drive, O_RDONLY, &dev, &boot, name, &media);
  41.     if(!Stream)
  42.         cleanup_and_exit(1);
  43.     FREE(&Stream);
  44.  
  45.     /* and finally mount it */
  46.     switch((pid=fork())){
  47.     case -1:
  48.         fprintf(stderr,"fork failed\n");
  49.         cleanup_and_exit(1);
  50.     case 0:
  51.         close(2);
  52.         open("/dev/null", O_RDWR);
  53.         argv[1] = "mount" ;
  54.         if ( argc > 2 )
  55.             execvp("mount", argv + 1 );
  56.         else
  57.             execlp("mount", "mount", name, 0);
  58.         perror("exec mount");
  59.         cleanup_and_exit(1);
  60.     default:
  61.         while ( wait(&status) != pid );
  62.     }    
  63.     if ( WEXITSTATUS(status) == 0 )
  64.         cleanup_and_exit(0);
  65.     argv[0] = "mount";
  66.     argv[1] = "-r";
  67.     if ( argc > 2 )
  68.         execvp("mount", argv);
  69.     else
  70.         execlp("mount", "mount","-r", name, 0);
  71.     cleanup_and_exit(1);
  72. }
  73.  
  74. #else /* linux */
  75.  
  76. #include "msdos.h"
  77.  
  78. void mmount(int argc, char **argv, int type)
  79. {
  80.   fprintf(stderr,"This command is only available for LINUX \n");
  81.   cleanup_and_exit(1);
  82. }
  83. #endif /* linux */
  84.  
  85.